package learner;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;


public class PatternReader {
	
	private JsonReader reader;
	
	public PatternReader() {
	}
	
	public ArrayList<Pattern> givePatterns(int patternNb){
		ArrayList<Pattern> patterns = new ArrayList<Pattern>();
		for(int i=1;;i++){
			try {
				reader = new JsonReader(new FileReader("patterns/pattern" + patternNb + "_" + i + ".json"));
				Pattern pat = readPattern();
				patterns.add(pat);
			} catch (FileNotFoundException e) {
				break;
			}
		}
		return patterns;
	}
	
	public Pattern readPattern() {
		Gson gson = new Gson();
		return gson.fromJson(reader, Pattern.class);
	}

	public Pattern giveTestPattern() {
		Gson gson = new Gson();
		try {
			reader = new JsonReader(new FileReader("testpattern/pattern.json"));
			return readPattern();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}

}

